//
//  UIButton+Extension.swift
//  01-新浪微博
//
//  Created by 陈许亚 on 16/3/14.
//  Copyright © 2016年 cxy. All rights reserved.
//

import UIKit

extension UIButton {
    //类方法1.有背景图片，自身图片
    //背景图片+图片的按钮
    class func buttonWithImage(imageName: String?,backImageName: String?) -> UIButton {
        let btn = UIButton()
        if backImageName != nil {
        //设置背景图片
        btn.setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: backImageName! + "highlighted"), forState: .Highlighted)
        }
        if imageName != nil{
        //设置图片
        btn.setImage(UIImage(named: imageName!), forState: .Normal)
        btn.setImage(UIImage(named: imageName! + "highlighted"), forState: .Highlighted)
        }
        btn.sizeToFit()
        return btn
    }
    //2，背景图片？ + 文字 + 图片
    class func buttonWithTitle(backImageName: String?,title: String,titleColor: UIColor,fontSizeOfTitle: CGFloat,imageName: String? = nil) -> UIButton {
        let btn = UIButton()
        if backImageName != nil {
            
            btn.setBackgroundImage(UIImage(named:backImageName!), forState: .Normal)
        }
        if imageName != nil {
            
            btn.setImage(UIImage(named: imageName!), forState: .Normal)
        }
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(titleColor, forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(fontSizeOfTitle)
        btn.sizeToFit()
        return btn

    }
    

}
